<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>提现申请</title>
    <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css" id="swicth-style">
    <link rel="stylesheet" type="text/css" href="/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/css/common.css">
    <link rel="stylesheet" type="text/css" href="/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/themes/color.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
</head>

<body class="easyui-layout" style="padding:5px;">
<fieldset>
    <legend>信息查询</legend>
    <form id="ffSearch" method="post">
        <div id="searchBar">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <th>申请状态：</th>
                    <td style="width:120px">
                        <select id="statusSelect" name="status" class="easyui-combobox" data-options="onSelect: function(rec){onSearch()}" style="width:100px">
                            <option value="0">全部</option>
                            <option value="1">完成</option>
                            <option value="2">申请提现</option>
                        </select>
                    </td>
                    <td colspan="2">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="onSearch()">查询</a>&nbsp;&nbsp;
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="onClear()">重置</a>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</fieldset>

<table id="dg"> </table>

<div id="launch" class="easyui-window" title="发起提现申请" data-options="closed:true,iconCls:'icon-save',footer:'#ft'" style="width:450px;height:300px;padding:10px;">
    <form id="ff" method="post">
        <table class="table-blue">
            <tr>
                <th>提现金额：</th>
                <td><input class="easyui-validatebox textbox" type="text" id = "amount" name="amount" data-options="required:true,validType:'maxLength[50]'"/></td>
            </tr>
        </table>
    </form>
    <span>当前可提现余额为</span><span id="balanceSpan"></span><a href="javascript:void(0)" onclick="withdrawalAll()">，全部提现</a>
    <div id="ft" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="submitForm()" style="width:80px">Ok</a> &nbsp;&nbsp;
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="closeWindow()" style="width:80px">Cancel</a>
    </div>
</div>


<script type="text/javascript">
    $(function(){
        var dg = $('#dg').datagrid();
        dg.datagrid({
            url:'/v1/api0/withdrawal/application',
            columns:[[
                {field:'id',hidden:true,title:'中控ID',width:100},
                {field:'name',title:'申请名称',width:100},
                {field:'creater',title:'发起人',width:100},
                {field:'amount',title:'提现金额',width:100},
                {field:'createTime',title:'发起时间',width:100,formatter: formatDateTime},
                {field:'remark',title:'备注',width:100},
                {field:'status',title:'申请状态',width:40,formatter: function(value,row,index){
                    switch(value) {
                        case 1: return "已完成";
                        case 2: return "申请提现";
                    }
                }}
            ]],
            title:'提现申请管理',
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: true,
            toolbar: [ {
                id: 'btnReload',
                text: '刷新',
                iconCls: 'icon-reload',
                handler: function () {
                    $("#dg").datagrid("reload");
                }
            }, '-', {
                id: 'btnLaunch',
                text: '发起',
                iconCls: 'icon-add',
                handler: function () {
                    launchApplication();
                }
            }]
        });

        var heightMargin = $("#searchBar").height() + 45;
        $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        $(window).resize(function() {
            $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        });
    });

    function onSearch(){
        var queryParams = $('#ffSearch').serializeObject();
        $('#dg').datagrid({
            url:'/v1/api0/withdrawal/application',
            queryParams: queryParams
        });
    }

    function onClear() {
        $('#ffSearch').form('clear');
        $('#statusSelect').combobox('setValue', '0');
        onSearch();
    }

    function closeWindow(){
        $('#launch').window('close');
         $("#amount").val("");//金额输入框设为空
    }

    function launchApplication() {
        $.ajax({
            type: "post",
            url: '/v1/api0/launch/application',
            datatype: "json",
            success: function (data) {
                if(data.code == 500){
                     top.window.showMessage(data.msg);
                }
                else{
                    $('#launch').window('open');
                    setBalance();
                }

            }
        });
    }
        function setBalance(){
             $.ajax({
            type: "post",
            url: '/v1/api0/launch/profitBalance',
            datatype: "json",
            success: function (data) {
                $("#balanceSpan").text(data.body);
            }
        });
        }

     function withdrawalAll(){
        var balance = $("#balanceSpan").text();
        $("#amount").val(balance);
     }

     function submitForm(){
           var amount = $("#amount").val();
           if(!checkNumber(amount)){
                top.window.showMessage("请输入合法的提现金额");
                return;
           }
          var data = $('#ff').serialize();
         $.ajax({
            type: "post",
            data: data,
            url: '/v1/api0/application/submit',
            datatype: "json",
            success: function (data) {
            if(data.code == 200){
            $('#dg').datagrid('reload');
                closeWindow();
            }
                top.window.showMessage(data.msg);
            }
          });
      }

    function checkNumber(input) {
 　　     var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/
　　      if (!re.test(input)) {
 　　　　       return false;
 　      　}else{
            return true;
            }
      }
</script>
</body>
</html>
